//
//  ShiLiTestSelectViewController.m
//  安好
//
//  Created by qinlongqing on 14-8-26.
//  Copyright (c) 2014年 冯凯. All rights reserved.
//

#import "ShiLiTestSelectViewController.h"

@interface ShiLiTestSelectViewController ()
{
    CGFloat buttonHeight;
    CGFloat buttonSpace;
    CGFloat kanBuQingButtonHeight;
}
@end

@implementation ShiLiTestSelectViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"shiLiTestSelectViewDidShow" object:nil];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:NO];

    [self makeNavBar];
    
    if (kScreenWidth == 414) {
        buttonHeight = 126;
        buttonSpace = 24;
        kanBuQingButtonHeight = 54;
    }
    else{
        buttonHeight = 105;
        buttonSpace = 20;
        kanBuQingButtonHeight = 45;
    }
    CGFloat space = (kScreenHeight - 64 - buttonHeight*2 - buttonSpace - kanBuQingButtonHeight)/3;
    
    
    self.view.backgroundColor = UIColorFromRGB(0xe7f1f4);
    
    NSMutableArray *tempArray = [self.shiLiTestData mutableCopy];
    
    UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake((kScreenWidth - buttonHeight*2 - buttonSpace)/2, space, buttonHeight, buttonHeight)];
    if (kScreenWidth == 414) {
        button1.titleLabel.font = [UIFont systemFontOfSize:37];
    }
    else{
        button1.titleLabel.font = [UIFont systemFontOfSize:35];
    }
    button1.layer.cornerRadius = 3;
    button1.backgroundColor = UIColorFromRGB(0x4fc1e9);
    [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    int j = arc4random() % 4;
    [button1 setTitle:[tempArray objectAtIndex:j] forState:UIControlStateNormal];
    [tempArray removeObjectAtIndex:j];
    [button1 addTarget:self action:@selector(doBTN:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
    
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(button1.frame.origin.x + button1.frame.size.width + buttonSpace, space, buttonHeight, buttonHeight)];
    if (kScreenWidth == 414) {
        button2.titleLabel.font = [UIFont systemFontOfSize:37];
    }
    else{
        button2.titleLabel.font = [UIFont systemFontOfSize:35];
    }
    button2.layer.cornerRadius = 3;
    button2.backgroundColor = UIColorFromRGB(0x4fc1e9);
    [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    j = arc4random() % 3;
    [button2 setTitle:[tempArray objectAtIndex:j] forState:UIControlStateNormal];
    [tempArray removeObjectAtIndex:j];
    [button2 addTarget:self action:@selector(doBTN:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
    UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake((kScreenWidth - buttonHeight*2 - buttonSpace)/2, button1.frame.origin.y + button1.frame.size.height +  buttonSpace, buttonHeight, buttonHeight)];
    if (kScreenWidth == 414) {
        button3.titleLabel.font = [UIFont systemFontOfSize:37];
    }
    else{
        button3.titleLabel.font = [UIFont systemFontOfSize:35];
    }
    button3.layer.cornerRadius = 3;
    button3.backgroundColor = UIColorFromRGB(0x4fc1e9);
    [button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    j = arc4random() % 2;
    [button3 setTitle:[tempArray objectAtIndex:j] forState:UIControlStateNormal];
    [tempArray removeObjectAtIndex:j];
    [button3 addTarget:self action:@selector(doBTN:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button3];
    
    UIButton *button4 = [[UIButton alloc]initWithFrame:CGRectMake(button3.frame.origin.x + button3.frame.size.width + buttonSpace, button2.frame.origin.y + button2.frame.size.height +  buttonSpace, buttonHeight, buttonHeight)];
    if (kScreenWidth == 414) {
        button4.titleLabel.font = [UIFont systemFontOfSize:37];
    }
    else{
        button4.titleLabel.font = [UIFont systemFontOfSize:35];
    }
    button4.layer.cornerRadius = 3;
    button4.backgroundColor = UIColorFromRGB(0x4fc1e9);
    [button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button4 setTitle:[tempArray lastObject] forState:UIControlStateNormal];
    [button4 addTarget:self action:@selector(doBTN:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button4];
    
    UIButton *kanBuQing = [[UIButton alloc]init];
    if (kScreenWidth == 414) {
        kanBuQing.frame = CGRectMake(20, button3.frame.origin.y + button3.frame.size.height + space*1.4, kScreenWidth - 40, kanBuQingButtonHeight);
        kanBuQing.titleLabel.font = [UIFont systemFontOfSize:22];
    }
    else{
        kanBuQing.frame = CGRectMake(15, button3.frame.origin.y + button3.frame.size.height + space*1.4, kScreenWidth - 30, kanBuQingButtonHeight);
        kanBuQing.titleLabel.font = [UIFont systemFontOfSize:20];
    }
    kanBuQing.layer.cornerRadius = 3;
    kanBuQing.backgroundColor = UIColorFromRGB(0x4fc1e9);
    [kanBuQing setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [kanBuQing setTitle:@"看不清" forState:UIControlStateNormal];
    [kanBuQing addTarget:self action:@selector(doBTN:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:kanBuQing];
    
}

- (void)makeNavBar{
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(doBack)];
    [backBtnImg setTintColor:[UIColor whiteColor]];
    self.navigationItem.leftBarButtonItem = backBtnImg;
}

-(void)doBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)doBTN:(UIButton *)sender{
    NSString *type = nil;
    if (self.currentTestEyeViewController.class == NSClassFromString(@"LeftEyeViewController")) {
         type = @"left";
    }
    else{
        type = @"right";
    }
    if ([sender.titleLabel.text isEqualToString:[self.shiLiTestData objectAtIndex:0]]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"nengKanQingChu" object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:type,@"type", nil]];
    }
    else{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"buNengQingChu" object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:type,@"type", nil]];
    }
}

- (void)dealloc{
    MyNSLog("视力测试选择界面释放");
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
